set SERVER_DIR=target\server

set CONF_VERSION="1.0"
echo "Please provide the version of the configuration to install with the application (default : 1.0)"
set /P INPUT=Type input [%CONF_VERSION%]: %=%
if "%INPUT%" == "" ( 
	rem donothing 
	echo Using default value
) else (
	echo Setting new version value
	set CONF_VERSION=%INPUT%
)
set INPUT=
echo "VERSION USED IS %CONF_VERSION%"

rem REPLACE in pomServer.xml the version value
@echo off
del pomServer.xml
for /F "delims= eol=" %%L in (pomServer.xml-template) DO (
        if "%%L"=="			<version>__VERSION_CONF__</version>" (
  echo ^<version^>%CONF_VERSION%^</version^> >>pomServer.xml
        ) ELSE (
  echo %%L>>pomServer.xml
        )
)
@echo on

cmd /c mvn dependency:copy-dependencies -fpomServer.xml -DoutputDirectory=%SERVER_DIR%

cmd /c mvn -f pomServer.xml dependency:list -DoutputFile=serverContent.txt


rem PARSE SERVER CONTENT TO MAKE IT EASIER TO USE
@echo off
echo ^<releaseContent^> > serverContent.xml
For /f "tokens=1,2,3,4 delims=: " %%a in (serverContent.txt) Do (
	if "%%a" == "The" (
		echo "comment" 
	) else (
		echo   ^<file^>  >> serverContent.xml
			echo     ^<name^>%%b^</name^> >> serverContent.xml
			echo     ^<version^>%%d^</version^> >> serverContent.xml
			echo     ^<extension^>%%c^</extension^> >> serverContent.xml
			echo     ^<groupeID^>%%a^</groupId^> >> serverContent.xml
		echo   ^</file^>  >> serverContent.xml
	)
)
echo ^</releaseContent^> >> serverContent.xml
@echo on
rem END OF PARSE

cd %SERVER_DIR%

echo "copy  MysqlConfiguration-1.0-SNAPSHOT.properties to org\agile\grenoble\data\MysqlConfiguration.properties"
copy  MysqlConfiguration-1.0-SNAPSHOT.properties org\agile\grenoble\data\Configuration.properties
set CLASSPATH=.;activation-1.1.jar;asm-3.1.jar;avalon-framework-4.1.3.jar;commons-logging-1.1.jar;grizzly-framework-1.9.18-i.jar;grizzly-http-1.9.18-i.jar;grizzly-http-servlet-1.9.18-i.jar;grizzly-portunif-1.9.18-i.jar;grizzly-rcm-1.9.18-i.jar;grizzly-servlet-webserver-1.9.18-i.jar;grizzly-utils-1.9.18-i.jar;jaxb-api-2.1.jar;jaxb-impl-2.1.jar;jersey-core-1.4.jar;jersey-server-1.4.jar;jsr-api-2.5.0.jar;log4j-1.2.16.jar;logkit-1.0.1.jar;mysqlconnector-5.0.8.jar;QuestionStorage-1.0-SNAPSHOT.jar;StorageServer-1.0-SNAPSHOT.jar;questiontype-1.0.0.jar;resolver-2.5.0.jar;servlet-api-2.3.jar;sqltools-2.0.0.jar;stax-api-1.0-2.jar;xbeans-2.5.0.jar;xbeans-qname-2.5.0.jar;xbeans-xpath-2.5.0.jar;xml-public-2.5.0.jar
java -classpath %CLASSPATH% org.agile.grenoble.Server

cd ..\..
